package Ventanas;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JRadioButton;

import java.awt.Choice;
import java.awt.Label;
import java.awt.Button;

import javax.swing.JButton;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JLabel;
import javax.swing.JSeparator;

import java.awt.SystemColor;

import javax.swing.border.SoftBevelBorder;
import javax.swing.border.BevelBorder;
import javax.swing.JTextArea;
import javax.swing.JScrollBar;

import Clases.Cliente;
import Clases.Producto;
import Gestores.gProductos;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.util.ArrayList;
import java.util.LinkedList;
import java.awt.Color;

public class vCatalogo extends JFrame {

	private JPanel contentPane;
	private JTextField textField;
	private JTextField textField_1;
	private JTextField textField_2;
	private JTextField textField_3;
	private int enviar;
	private double total;
	private int puntos;
	private JTextField txte;
	private JTextField txte_1;
	private JTextField textField_4;
	private JTextField textField_5;
	private JTextField textField_6;

	/**
	 * Launch the application.
	 */
	/*public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					vCatalogo frame = new vCatalogo();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}
*/
	/**
	 * Create the frame.
	 */
	public vCatalogo(final Cliente c, ArrayList<Producto> aProductos) {
		
		final LinkedList aCompras =new LinkedList();
		
		
		
		
		
		setResizable(false);
		setTitle("Catalogo ");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 849, 593);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		final Choice choice = new Choice();
		choice.addItem("Placas base");
		choice.addItem("Procesadores");
		choice.addItem("Tarjetas graficas");
		choice.addItem("Discos duros");
		choice.setBounds(146, 10, 166, 20);
		contentPane.add(choice);
		
		Label label = new Label("Seleccionar producto");
		label.setBounds(10, 10, 180, 22);
		contentPane.add(label);
		
		JButton btnNewButton = new JButton("");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				vInicioCliente.vSC.setVisible(true);
				setVisible(false);	
			}
		});
		btnNewButton.setIcon(new ImageIcon(vCatalogo.class.getResource("/Img/arrow_left.png")));
		btnNewButton.setBounds(10, 38, 89, 23);
		contentPane.add(btnNewButton);
		
		textField = new JTextField();
		textField.setEditable(false);
		textField.setBounds(503, 10, 36, 20);
		contentPane.add(textField);
		textField.setText(Integer.toString(c.getPuntos_acumulados()));
		textField.setColumns(10);
		
		Label label_1 = new Label("Total numero de productos:");
		label_1.setBounds(345, 10, 158, 22);
		contentPane.add(label_1);
		
		JLabel lblCarritoDeLa = new JLabel("Carrito de la compra :");
		lblCarritoDeLa.setIcon(new ImageIcon(vCatalogo.class.getResource("/Img/cart.png")));
		lblCarritoDeLa.setBounds(549, 13, 147, 14);
		contentPane.add(lblCarritoDeLa);
		
		textField_1 = new JTextField();
		textField_1.setEditable(false);
		textField_1.setBounds(700, 10, 86, 20);
		contentPane.add(textField_1);
		textField_1.setColumns(10);
		
		JLabel lblNewLabel = new JLabel("");
		lblNewLabel.setIcon(new ImageIcon(vCatalogo.class.getResource("/Img/money_euro.png")));
		lblNewLabel.setBounds(796, 10, 46, 20);
		contentPane.add(lblNewLabel);
		
	
		
		JSeparator separator = new JSeparator();
		separator.setBounds(10, 85, 813, 2);
		contentPane.add(separator);
		
		final JPanel panel = new JPanel();
		
		
		//
		panel.setVisible(false);
		//
		
		panel.setBorder(new SoftBevelBorder(BevelBorder.LOWERED, null, null, null, null));
		panel.setBackground(SystemColor.activeCaptionBorder);
		panel.setBounds(10, 96, 813, 450);
		contentPane.add(panel);
		panel.setLayout(null);
		
		JLabel lblNewLabel_2 = new JLabel("New label");
		lblNewLabel_2.setBounds(10, 83, 46, 38);
		lblNewLabel_2.setIcon(new ImageIcon(vCatalogo.class.getResource("/Img/offer.png")));
		panel.add(lblNewLabel_2);
		
		JLabel lblNewLabel_1 = new JLabel("New label");
		lblNewLabel_1.setBounds(10, 11, 155, 120);
		lblNewLabel_1.setText("01");
		lblNewLabel_1.setIcon(new ImageIcon(vCatalogo.class.getResource("/Img/Placa_base_1.jpg")));
		panel.add(lblNewLabel_1);
		
		textField_2 = new JTextField();
		textField_2.setEditable(false);
		
		textField_2.setBounds(491, 41, 46, 20);
		contentPane.add(textField_2);
		textField_2.setColumns(10);
		
		JTextArea textArea = new JTextArea();
		textArea.setBounds(175, 11, 599, 120);
		textArea.setEditable(false);
		textArea.setLineWrap(true);
		panel.add(textArea);
		
		final JButton btnEliminar = new JButton("Eliminar");
		btnEliminar.setBounds(111, 135, 89, 23);
		btnEliminar.setEnabled(false);
		btnEliminar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				int codigo=01;
				double total=0;
				
				for(int i=0;i<c.getlHistorialCompras().size();i++){
					if( c.getlHistorialCompras().get(i)=="01"){
						c.getlHistorialCompras().remove(i);			
					}			
				}
			total=	gProductos.getgClientes().borrarProductoCompra(codigo, aCompras);
			textField_2.setText(Integer.toString((int) gProductos.getgClientes().calcularPuntos(01, aCompras)));
				textField_1.setText(Integer.toString((int) total));
			/*	
				System.out.println("-------------------------------------");
				for(int i=0;i<c.getlHistorialCompras().size();i++){
					System.out.println(c.getlHistorialCompras().get(i));
				}
				System.out.println("-------------------------------------");
				*/
			}
		});
		panel.add(btnEliminar);
		
		
		JButton btnAadir_producto_1_pb = new JButton("A\u00F1adir ");
		btnAadir_producto_1_pb.setBounds(10, 135, 89, 23);
		btnAadir_producto_1_pb.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				btnEliminar.setEnabled(true);
				aCompras.add(01);
				
				c.getlHistorialCompras().add(01); 
			/*
				System.out.println("----------------------------------");
				for(int i=0;i<c.getlHistorialCompras().size();i++){
					System.out.println(c.getlHistorialCompras().get(i));
				}
				System.out.println("-----------------------------------");
				*/
				
				total=gProductos.getgClientes().calcularTotalPedido(aCompras);
				textField_1.setText(Integer.toString((int) total));
				textField_2.setText(Integer.toString((int) gProductos.getgClientes().calcularPuntos(01, aCompras)));
				
			}
		});
		panel.add(btnAadir_producto_1_pb);
		
		final JButton btnFinalizarCompra = new JButton("Finalizar compra");
		btnFinalizarCompra.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				puntos=(int) gProductos.getgClientes().calcularPuntos(01, aCompras);
				
				total=gProductos.getgClientes().calcularTotalPedido(aCompras);
				vInicioCliente.vFC=new vFinalizarCompra(c,total,puntos);
				vInicioCliente.vFC.setVisible(true);
				setVisible(false);
				
			}
		});
		
		final JPanel panel_1 = new JPanel();
		panel_1.setBounds(10, 98, 823, 448);
		contentPane.add(panel_1);
		panel_1.setLayout(null);
		
		JButton btnAadir = new JButton("A\u00F1adir");
		btnAadir.setBounds(10, 135, 89, 23);
		panel_1.add(btnAadir);
		
		JLabel lblNewLabel_5 = new JLabel("PRODUCTO 01");
		lblNewLabel_5.setForeground(Color.BLUE);
		lblNewLabel_5.setBounds(10, 11, 155, 120);
		panel_1.add(lblNewLabel_5);
		
		JTextArea textArea_3 = new JTextArea();
		textArea_3.setBounds(175, 11, 599, 120);
		panel_1.add(textArea_3);
		
		JLabel lblNewLabel_6 = new JLabel("Precio :");
		lblNewLabel_6.setBounds(220, 142, 46, 14);
		panel_1.add(lblNewLabel_6);
		
		JButton btnEliminar_1 = new JButton("Eliminar");
		btnEliminar_1.setBounds(111, 135, 89, 23);
		panel_1.add(btnEliminar_1);
		
		JButton button_4 = new JButton("A\u00F1adir");
		button_4.setBounds(10, 292, 89, 23);
		panel_1.add(button_4);
		
		JButton button_5 = new JButton("Eliminar");
		button_5.setBounds(111, 292, 89, 23);
		panel_1.add(button_5);
		
		JLabel lblPrecio_1 = new JLabel("Precio :");
		lblPrecio_1.setBounds(220, 296, 46, 14);
		panel_1.add(lblPrecio_1);
		
		JLabel lblNewLabel_7 = new JLabel("PRODUCTO 02");
		lblNewLabel_7.setForeground(Color.BLUE);
		lblNewLabel_7.setBounds(10, 169, 162, 100);
		panel_1.add(lblNewLabel_7);
		
		JTextArea textArea_4 = new JTextArea();
		textArea_4.setBounds(175, 163, 599, 120);
		panel_1.add(textArea_4);
		
		textField_4 = new JTextField();
		textField_4.setBounds(263, 293, 46, 20);
		panel_1.add(textField_4);
		textField_4.setColumns(10);
		
		textField_5 = new JTextField();
		textField_5.setBounds(263, 136, 61, 20);
		panel_1.add(textField_5);
		textField_5.setColumns(10);
		
		JLabel lblNewLabel_8 = new JLabel("New label");
		lblNewLabel_8.setBounds(10, 326, 155, 89);
		panel_1.add(lblNewLabel_8);
		
		JButton button_6 = new JButton("A\u00F1adir");
		button_6.setBounds(0, 414, 89, 23);
		panel_1.add(button_6);
		
		JButton button_7 = new JButton("Eliminar");
		button_7.setBounds(111, 414, 89, 23);
		panel_1.add(button_7);
		
		JLabel label_4 = new JLabel("Precio :");
		label_4.setBounds(220, 418, 46, 14);
		panel_1.add(label_4);
		
		textField_6 = new JTextField();
		textField_6.setColumns(10);
		textField_6.setBounds(263, 415, 46, 20);
		panel_1.add(textField_6);
		
		JTextArea textArea_5 = new JTextArea();
		textArea_5.setBounds(175, 326, 588, 77);
		panel_1.add(textArea_5);
		btnFinalizarCompra.setBounds(559, 38, 254, 26);
		contentPane.add(btnFinalizarCompra);
		
		JLabel lblPrecio = new JLabel("Precio :");
		lblPrecio.setBounds(220, 142, 46, 14);
		panel.add(lblPrecio);
		
		textField_3 = new JTextField();
		textField_3.setBounds(264, 136, 38, 20);
		textField_3.setText("70E");
		textField_3.setEditable(false);
		panel.add(textField_3);
		textField_3.setColumns(10);
		
		JScrollBar scrollBar = new JScrollBar();
		scrollBar.setBounds(796, 0, 17, 448);
		panel.add(scrollBar);
		
	
		
		JLabel lblNewLabel_3 = new JLabel("PRODUCTO 02");
		lblNewLabel_3.setBounds(10, 166, 155, 120);
		
		lblNewLabel_3.setForeground(Color.BLUE);
		lblNewLabel_3.setBackground(Color.BLUE);
		panel.add(lblNewLabel_3);
		
		final JButton button_1 = new JButton("Eliminar");
		button_1.setBounds(111, 285, 89, 23);
		button_1.setEnabled(false);
		panel.add(button_1);
		
		JButton button = new JButton("A\u00F1adir ");
		button.setBounds(10, 285, 89, 23);
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				button_1.setEnabled(true);
				aCompras.add(02);
				
				c.getlHistorialCompras().add(02); 
			/*
				System.out.println("----------------------------------");
				for(int i=0;i<c.getlHistorialCompras().size();i++){
					System.out.println(c.getlHistorialCompras().get(i));
				}
				System.out.println("-----------------------------------");
				*/
				
				total=gProductos.getgClientes().calcularTotalPedido(aCompras);
				textField_1.setText(Integer.toString((int) total));
				textField_2.setText(Integer.toString((int) gProductos.getgClientes().calcularPuntos(01, aCompras)));
			}
		});
		panel.add(button);
		
	
		
		JLabel label_2 = new JLabel("Precio :");
		label_2.setBounds(220, 289, 46, 14);
		panel.add(label_2);
		
		txte = new JTextField();
		txte.setBounds(264, 286, 38, 20);
		txte.setText("120E");
		txte.setEditable(false);
		txte.setColumns(10);
		panel.add(txte);
		
		JTextArea textArea_1 = new JTextArea();
		textArea_1.setBounds(175, 165, 599, 109);
		textArea_1.setLineWrap(true);
		textArea_1.setEditable(false);
		panel.add(textArea_1);
		
		JLabel lblNewLabel_4 = new JLabel("PRODUCTO 03");
		lblNewLabel_4.setBounds(10, 319, 155, 83);
		lblNewLabel_4.setForeground(Color.BLUE);
		panel.add(lblNewLabel_4);
		
		JButton button_2 = new JButton("A\u00F1adir ");
		button_2.setBounds(10, 414, 89, 23);
		panel.add(button_2);
		
		JButton button_3 = new JButton("Eliminar");
		button_3.setBounds(111, 414, 89, 23);
		panel.add(button_3);
		
		JLabel label_3 = new JLabel("Precio :");
		label_3.setBounds(220, 418, 46, 14);
		panel.add(label_3);
		
		txte_1 = new JTextField();
		txte_1.setBounds(264, 415, 38, 20);
		txte_1.setText("100E");
		txte_1.setEditable(false);
		txte_1.setColumns(10);
		panel.add(txte_1);
		
		JTextArea textArea_2 = new JTextArea();
		textArea_2.setBounds(175, 314, 599, 94);
		textArea_2.setLineWrap(true);
		textArea_2.setEditable(false);
		panel.add(textArea_2);
		
		JLabel lblPuntos = new JLabel("Puntos acumulables:");
		lblPuntos.setBounds(345, 38, 147, 23);
		contentPane.add(lblPuntos);
		
		JButton btnCargar = new JButton("Cargar");
		btnCargar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {

				switch (choice.getSelectedIndex()){
				
				case 0:
					panel.setVisible(true);
					panel_1.setVisible(false);
					panel.updateUI();
					break;
					
				case 1:
					panel.setVisible(false);
					panel_1.setVisible(true);
					panel.updateUI();
					break;
				
				
				
				}
				
			}
		});
		btnCargar.setBounds(146, 36, 166, 23);
		contentPane.add(btnCargar);
		
		panel.setVisible(true);
		panel_1.setVisible(false);
		
		
		
		
		
		
		
	
	}
}
